package cn.south.campus.business.controller;

import cn.south.campus.business.model.req.ApplyTakeRecordReq;
import cn.south.campus.business.model.req.ExpressTakeReq;
import cn.south.campus.business.model.req.RecordReq;
import cn.south.campus.business.model.vo.ExpressApplyVo;
import cn.south.campus.business.model.vo.ExpressTakeDetailVo;
import cn.south.campus.business.model.vo.ExpressTakeOrderVo;
import cn.south.campus.business.model.vo.ExpressTakeVo;
import cn.south.campus.business.service.ExpressTakeService;
import cn.south.campus.common.model.bo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 快递代取 前端控制器
 * </p>
 *
 * @author chow
 * @since 2024-12-13
 */
@RestController
@RequestMapping("/campus/expressTake")
@AllArgsConstructor
public class ExpressTakeController {

    private final ExpressTakeService expressTakeService;

    @PostMapping("publish")
    public Result<String> publish(@RequestBody ExpressTakeVo expressTakeVo) {
        String orderNo = expressTakeService.publish(expressTakeVo);
        return Result.success(orderNo);
    }

    @PutMapping("/pay")
    public Result<String> pay(@NotNull(message = "订单编号不能为空") String orderNo, @NotNull(message = "支付方式不能为空") String payMethod) {
        expressTakeService.payOrder(orderNo, payMethod);
        return Result.success("支付成功");
    }

    @GetMapping("page")
    public Result<IPage<ExpressTakeVo>> pageQuery(ExpressTakeReq req) {
        IPage<ExpressTakeVo> res = expressTakeService.pageQuery(req);
        return Result.success(res);
    }

    @GetMapping("pageMe")
    public Result<IPage<ExpressTakeVo>> pageQueryMe(ExpressTakeReq req) {
        IPage<ExpressTakeVo> res = expressTakeService.pageQueryMe(req);
        return Result.success(res);
    }

    @GetMapping("detail/{id}")
    public Result<ExpressTakeVo> detail(@PathVariable Long id) {
        ExpressTakeVo res = expressTakeService.getDetail(id);
        return Result.success(res);
    }

    @GetMapping("detailMe/{id}")
    public Result<ExpressTakeVo> detailMe(@PathVariable Long id) {
        ExpressTakeVo res = expressTakeService.getDetailMe(id);
        return Result.success(res);
    }

    @DeleteMapping("delete/{id}")
    public Result<String> delete(@PathVariable Long id) {
        expressTakeService.delete(id);
        return Result.success("删除成功");
    }

    @PutMapping("cancel/{id}")
    public Result<String> cancel(@PathVariable Long id) {
        expressTakeService.cancel(id);
        return Result.success("取消成功");
    }

    @PostMapping("apply/{id}")
    public Result<String> apply(@PathVariable Long id) {
        expressTakeService.apply(id);
        return Result.success("申请成功");
    }

    @PutMapping("accept/{id}")
    public Result<String> accept(@PathVariable Long id) {
        expressTakeService.accept(id);
        return Result.success("接受成功");
    }

    @GetMapping("applyRecord")
    public Result<List<ExpressApplyVo>> applyRecord(RecordReq req) {
        List<ExpressApplyVo> res = expressTakeService.applyRecord(req.getTakeId(), req.getKeyword());
        return Result.success(res);
    }

    @GetMapping("myApplyExpress")
    public Result<IPage<ExpressTakeVo>> myApplyExpress(ApplyTakeRecordReq req) {
        IPage<ExpressTakeVo> res = expressTakeService.queryMyApplyExpress(req);
        return Result.success(res);
    }

    @GetMapping("getByOrderNo/{orderNo}")
    public Result<ExpressTakeOrderVo> getByOrderNo(@PathVariable String orderNo) {
        ExpressTakeOrderVo res = expressTakeService.takeOrder(orderNo);
        return Result.success(res);
    }

    @GetMapping("getTakeByOrderNo/{orderNo}")
    public Result<ExpressTakeVo> getTakeByOrderNo(@PathVariable String orderNo) {
        ExpressTakeVo res = expressTakeService.getTakeByOrderNo(orderNo);
        return Result.success(res);
    }

    @GetMapping("showTakeInfo/{takeId}")
    public Result<List<ExpressTakeDetailVo>> showTakeInfo(@PathVariable Long takeId) {
        return Result.success(expressTakeService.showTakeInfo(takeId));
    }

    @PutMapping("confirmSend/{takeId}")
    public Result<String> confirmSend(@PathVariable Long takeId) {
        expressTakeService.confirmSend(takeId);
        return Result.success("送达成功");
    }

    @PutMapping("confirmReceive/{takeId}")
    public Result<String> confirmReceive(@PathVariable Long takeId) {
        expressTakeService.confirmReceive(takeId);
        return Result.success("确认收货成功");
    }
}
